package com.joejag.mavenstats.client.utils;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;

public class ImageHyperlink extends Hyperlink
{
  private ImageHyperlinkAction action;

  public interface ImageHyperlinkAction
  {
    public void performAction();
  }

  public ImageHyperlink(Image img, ImageHyperlinkAction action)
  {
    super();
    this.action = action;

    DOM.appendChild(DOM.getFirstChild(getElement()), img.getElement());
    img.unsinkEvents(Event.ONCLICK | Event.MOUSEEVENTS);
    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS);
  }

  public void onBrowserEvent(Event event)
  {
    super.onBrowserEvent(event);
    switch (DOM.eventGetType(event))
    {
      case Event.ONMOUSEDOWN:
        action.performAction();
    }
  }
}